/*
 * TimerTester.cpp
 *
 *  Created on: Nov 4, 2014
 *      Author: root
 */

#include "Timer.h"
#include <string>

using namespace std;
using namespace TimerNameSpace;

void* PrintHello(void* a)
{
	while(1)
	{
		std::cout << "Hello World with Parameter "<<  (int)a << endl;
		sleep(1);
	}
   return (void*)((int)a+1);
}

int main ()
{
	Timer timer;


//Test TimeOutFunc method with Parameter to function
std::cout << "Test TimeOutFunc method with Parameter to function:" << std::endl;
std::cout << "call PrintHello method and set TimeOut to 4 seconds..." << std::endl;
sleep(5);
std::cout << "Starting..." << std::endl;
int param=10;
void* a=timer.TimeOutFunc(PrintHello, (void*)param, 4); //calling TimeOutFunc
if ((int)a!=-1)
	cout<<"Thread finished and returned the int "<<(int)a << endl<< endl;
else
	cout<<"Timeout!"<<endl<< endl;

//Test CountDown method
std::cout << "Test CountDown method:" << std::endl;
sleep(3);
std::cout << "Starting..." << std::endl;
	signed int sec=3;
if (timer.CountDown(&sec)) //calling CountDown
	while(sec!=0)
		std::cout << "Remaining time: " <<sec<<" seconds."<< std::endl;



std::cout << "Waiting 3 sec for terminating..." << std::endl;
sleep(3);
std::cout << "Finish TimerTesting" << std::endl;

return 0;
   }
